package view.bookAdmiView;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import dao.BookDao;
import dao.BookTypeDao;
import model.Book;
import model.BookType;
import util.DbUtil;
import util.StringUtil;

import java.awt.Font;
import javax.swing.ImageIcon;
import java.awt.Color;

public class BookSearchInterFrm extends JInternalFrame {
	private JTable bookTable;
	private JTextField s_bookNameTxt;
	private JTextField s_authorTxt;
	private JComboBox s_bookTypeJcb;
	private JRadioButton manJrb;
	private JRadioButton femaleJrb ;
	private JTextArea bookDescTxt;
	private JComboBox bookTypeJcb;
	private JRadioButton notBorrowedJrb ;
	private JRadioButton borrowedJrb;
	private JRadioButton s_notBorrowedJrb;
	private JRadioButton s_borrowedJrb;
	
	private DbUtil dbUtil=new DbUtil();
	private BookTypeDao bookTypeDao=new BookTypeDao();
	private BookDao bookDao=new BookDao();
	
	private JTextField idTxt;
	private JTextField bookNameTxt;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JTextField priceTxt;
	private JTextField authorTxt;
	private final ButtonGroup buttonGroup_1 = new ButtonGroup();
	private final ButtonGroup buttonGroup_2 = new ButtonGroup();
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BookManageInterFrm frame = new BookManageInterFrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public BookSearchInterFrm() {
		getContentPane().setBackground(new Color(224, 255, 255));
		setClosable(true);
		setIconifiable(true);
		setTitle("图书查询");
		setBounds(100, 100, 1862, 899);
		
		JScrollPane bookImfScrollPane = new JScrollPane();
		
		JPanel bookSearchPanel = new JPanel();
		bookSearchPanel.setBackground(new Color(255, 255, 224));
		bookSearchPanel.setBorder(new TitledBorder(null, "\u641C\u7D22\u6761\u4EF6", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JPanel bookPanel = new JPanel();
		bookPanel.setBackground(new Color(255, 255, 224));
		bookPanel.setBorder(new TitledBorder(null, "\u8868\u5355\u64CD\u4F5C", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		
		JLabel title = new JLabel("图书查询");
		title.setIcon(new ImageIcon(BookSearchInterFrm.class.getResource("/images/bookAdmi/图书查询标题.png")));
		title.setFont(new Font("楷体", Font.BOLD, 40));
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addContainerGap()
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false)
								.addComponent(bookSearchPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(bookPanel, GroupLayout.PREFERRED_SIZE, 775, Short.MAX_VALUE))
							.addGap(55)
							.addComponent(bookImfScrollPane, GroupLayout.DEFAULT_SIZE, 831, Short.MAX_VALUE))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(646)
							.addComponent(title)))
					.addContainerGap())
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(24)
					.addComponent(title)
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addComponent(bookSearchPanel, GroupLayout.PREFERRED_SIZE, 210, GroupLayout.PREFERRED_SIZE)
							.addGap(49)
							.addComponent(bookPanel, GroupLayout.PREFERRED_SIZE, 443, GroupLayout.PREFERRED_SIZE))
						.addComponent(bookImfScrollPane, GroupLayout.PREFERRED_SIZE, 692, GroupLayout.PREFERRED_SIZE))
					.addGap(100))
		);
		
		JLabel id = new JLabel("编号：");
		id.setFont(new Font("宋体", Font.BOLD, 25));
		
		idTxt = new JTextField();
		idTxt.setFont(new Font("宋体", Font.BOLD, 25));
		idTxt.setEditable(false);
		idTxt.setColumns(10);
		
		JLabel bookName = new JLabel("图书名称：");
		bookName.setFont(new Font("宋体", Font.BOLD, 25));
		
		bookNameTxt = new JTextField();
		bookNameTxt.setFont(new Font("宋体", Font.BOLD, 25));
		bookNameTxt.setColumns(10);
		
		JLabel author = new JLabel("作者性别：");
		author.setFont(new Font("宋体", Font.BOLD, 25));
		
		manJrb = new JRadioButton("男");
		manJrb.setBackground(new Color(255, 255, 224));
		manJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup.add(manJrb);
		manJrb.setSelected(true);
		
		femaleJrb = new JRadioButton("女");
		femaleJrb.setBackground(new Color(255, 255, 224));
		femaleJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup.add(femaleJrb);
		
		JLabel price = new JLabel("价格：");
		price.setFont(new Font("宋体", Font.BOLD, 25));
		
		priceTxt = new JTextField();
		priceTxt.setFont(new Font("宋体", Font.BOLD, 25));
		priceTxt.setColumns(10);
		
		JLabel lblNewLabel_7 = new JLabel("图书作者：");
		
		authorTxt = new JTextField();
		authorTxt.setColumns(10);
		
		JLabel bookType = new JLabel("图书类别：");
		bookType.setFont(new Font("宋体", Font.BOLD, 25));
		
		bookTypeJcb = new JComboBox();
		bookTypeJcb.setFont(new Font("宋体", Font.BOLD, 25));
		
		JLabel bookDesc = new JLabel("图书描述：");
		bookDesc.setFont(new Font("宋体", Font.BOLD, 25));
		
		bookDescTxt = new JTextArea();
		bookDescTxt.setFont(new Font("宋体", Font.BOLD, 25));
		
		JLabel status = new JLabel("借阅状态：");
		status.setFont(new Font("宋体", Font.BOLD, 25));
		
		notBorrowedJrb = new JRadioButton("在馆");
		notBorrowedJrb.setBackground(new Color(255, 255, 224));
		notBorrowedJrb.setFont(new Font("宋体", Font.BOLD, 25));
		notBorrowedJrb.setSelected(true);
		buttonGroup_1.add(notBorrowedJrb);
		
		borrowedJrb = new JRadioButton("已借");
		borrowedJrb.setBackground(new Color(255, 255, 224));
		borrowedJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup_1.add(borrowedJrb);
		GroupLayout gl_bookPanel = new GroupLayout(bookPanel);
		gl_bookPanel.setHorizontalGroup(
			gl_bookPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_bookPanel.createSequentialGroup()
					.addGap(27)
					.addGroup(gl_bookPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_bookPanel.createParallelGroup(Alignment.LEADING, false)
							.addGroup(gl_bookPanel.createSequentialGroup()
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(price)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(priceTxt))
							.addGroup(gl_bookPanel.createSequentialGroup()
								.addComponent(id)
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(idTxt, GroupLayout.PREFERRED_SIZE, 161, GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_bookPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_bookPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(bookDesc)
								.addGroup(gl_bookPanel.createSequentialGroup()
									.addComponent(bookType)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(bookTypeJcb, GroupLayout.PREFERRED_SIZE, 158, GroupLayout.PREFERRED_SIZE)))))
					.addGap(88)
					.addGroup(gl_bookPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_bookPanel.createSequentialGroup()
							.addComponent(bookName)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, 158, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_bookPanel.createSequentialGroup()
							.addComponent(author)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(manJrb)
							.addGap(40)
							.addComponent(femaleJrb)
							.addGap(564)
							.addComponent(lblNewLabel_7)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(authorTxt, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_bookPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(status)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(notBorrowedJrb)
							.addGap(18)
							.addComponent(borrowedJrb))))
				.addGroup(Alignment.TRAILING, gl_bookPanel.createSequentialGroup()
					.addContainerGap(163, Short.MAX_VALUE)
					.addComponent(bookDescTxt, GroupLayout.PREFERRED_SIZE, 526, GroupLayout.PREFERRED_SIZE)
					.addGap(779))
		);
		gl_bookPanel.setVerticalGroup(
			gl_bookPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_bookPanel.createSequentialGroup()
					.addGap(22)
					.addGroup(gl_bookPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(id)
						.addComponent(idTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(bookName)
						.addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGroup(gl_bookPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_bookPanel.createParallelGroup(Alignment.BASELINE)
							.addComponent(lblNewLabel_7)
							.addComponent(authorTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_bookPanel.createSequentialGroup()
							.addGap(19)
							.addGroup(gl_bookPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(price)
								.addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(author)
								.addComponent(manJrb)
								.addComponent(femaleJrb))
							.addGap(30)
							.addGroup(gl_bookPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(bookType)
								.addComponent(bookTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(borrowedJrb)
								.addComponent(status)
								.addComponent(notBorrowedJrb))))
					.addGap(42)
					.addGroup(gl_bookPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(bookDescTxt, GroupLayout.PREFERRED_SIZE, 159, GroupLayout.PREFERRED_SIZE)
						.addComponent(bookDesc))
					.addGap(272))
		);
		bookPanel.setLayout(gl_bookPanel);
		
		JLabel s_bookName = new JLabel("图书名称：");
		s_bookName.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_bookNameTxt = new JTextField();
		s_bookNameTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_bookNameTxt.setColumns(10);
		
		JLabel s_author = new JLabel("图书作者：");
		s_author.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_authorTxt = new JTextField();
		s_authorTxt.setFont(new Font("宋体", Font.BOLD, 25));
		s_authorTxt.setColumns(10);
		
		JLabel s_bookType = new JLabel("图书类别：");
		s_bookType.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_bookTypeJcb = new JComboBox();
		s_bookTypeJcb.setFont(new Font("宋体", Font.BOLD, 25));
		
		JButton searchButton = new JButton("查询");
		searchButton.setIcon(new ImageIcon(BookSearchInterFrm.class.getResource("/images/bookAdmi/查询.png")));
		searchButton.setFont(new Font("宋体", Font.BOLD, 25));
		searchButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				bookSearchActionPerformed(e);
			}
		});
		
		JLabel s_status = new JLabel("借阅状态：");
		s_status.setFont(new Font("宋体", Font.BOLD, 25));
		
		s_notBorrowedJrb = new JRadioButton("在馆");
		s_notBorrowedJrb.setBackground(new Color(255, 255, 224));
		s_notBorrowedJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup_2.add(s_notBorrowedJrb);
		s_notBorrowedJrb.setSelected(true);
		
		s_borrowedJrb = new JRadioButton("已借");
		s_borrowedJrb.setBackground(new Color(255, 255, 224));
		s_borrowedJrb.setFont(new Font("宋体", Font.BOLD, 25));
		buttonGroup_2.add(s_borrowedJrb);
		
		JButton s_cancelButton = new JButton("取消");
		s_cancelButton.setIcon(new ImageIcon(BookSearchInterFrm.class.getResource("/images/bookAdmi/重置.png")));
		s_cancelButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				resetValueActionPerformed(e);
			}
		});
		s_cancelButton.setFont(new Font("宋体", Font.BOLD, 25));
		GroupLayout gl_bookSearchPanel = new GroupLayout(bookSearchPanel);
		gl_bookSearchPanel.setHorizontalGroup(
			gl_bookSearchPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_bookSearchPanel.createSequentialGroup()
					.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_bookSearchPanel.createSequentialGroup()
							.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.LEADING, false)
								.addGroup(gl_bookSearchPanel.createSequentialGroup()
									.addComponent(s_bookName)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(s_bookNameTxt, GroupLayout.PREFERRED_SIZE, 152, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_bookSearchPanel.createSequentialGroup()
									.addComponent(s_bookType)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.LEADING)
										.addComponent(searchButton)
										.addComponent(s_bookTypeJcb, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
							.addGap(32)
							.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.LEADING)
								.addGroup(gl_bookSearchPanel.createSequentialGroup()
									.addComponent(s_author)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(s_authorTxt, GroupLayout.PREFERRED_SIZE, 156, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_bookSearchPanel.createSequentialGroup()
									.addComponent(s_status)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(s_notBorrowedJrb)
									.addPreferredGap(ComponentPlacement.UNRELATED)
									.addComponent(s_borrowedJrb))))
						.addGroup(gl_bookSearchPanel.createSequentialGroup()
							.addGap(386)
							.addComponent(s_cancelButton)))
					.addContainerGap(107, Short.MAX_VALUE))
		);
		gl_bookSearchPanel.setVerticalGroup(
			gl_bookSearchPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_bookSearchPanel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(s_bookName)
						.addComponent(s_bookNameTxt, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
						.addComponent(s_author)
						.addComponent(s_authorTxt, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE))
					.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_bookSearchPanel.createSequentialGroup()
							.addGap(12)
							.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(s_bookType)
								.addComponent(s_bookTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
						.addGroup(gl_bookSearchPanel.createSequentialGroup()
							.addGap(18)
							.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.BASELINE)
								.addComponent(s_status)
								.addComponent(s_notBorrowedJrb)
								.addComponent(s_borrowedJrb))))
					.addGap(18)
					.addGroup(gl_bookSearchPanel.createParallelGroup(Alignment.LEADING)
						.addComponent(s_cancelButton)
						.addComponent(searchButton))
					.addContainerGap(14, Short.MAX_VALUE))
		);
		bookSearchPanel.setLayout(gl_bookSearchPanel);
		
		bookTable = new JTable();
		bookTable.setBackground(new Color(250, 235, 215));//设置表格背景颜色
		bookTable.getTableHeader().setFont(new Font("微软雅黑",Font.BOLD,20));//设置表格开头字体
		bookTable.getTableHeader().setBackground(new Color(127, 255, 212));//设置表格开头背景颜色
		bookTable.setFont(new Font("楷体", Font.BOLD, 22));//设置表格内容字体
		bookTable.setForeground(new Color(0,0,0));//设置表格内容字体颜色		
		bookTable.setRowHeight(bookTable.getRowHeight()+20);//设置表格内容的行高
		
		bookTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent met) {
				bookTableMousePressed(met);
				
			}
		});
		bookTable.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"\u7F16\u53F7", "\u56FE\u4E66\u540D\u79F0", "\u56FE\u4E66\u4F5C\u8005", "\u4F5C\u8005\u6027\u522B", "\u56FE\u4E66\u4EF7\u683C", "\u56FE\u4E66\u63CF\u8FF0", "\u56FE\u4E66\u7C7B\u522B", "\u501F\u9605\u72B6\u6001"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, false, false, false, false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		bookTable.getColumnModel().getColumn(5).setPreferredWidth(145);
		bookImfScrollPane.setViewportView(bookTable);
		getContentPane().setLayout(groupLayout);

		
		//设置文本域边框
		bookDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185),1,false));
				
		
		//设置JFrame居中显示
		this.setLocation(30, 0);
				
		this.fillBookType("search");
		
		this.fillBookType("modify");
		
		this.fillTable(new Book());
	}

	/**
	 * 取消查询事件处理
	 * @param e
	 */
	private void resetValueActionPerformed(ActionEvent e) {
		this.reSetValue();
		
	}

	/**
	 * 表格行点击事件处理
	 * @param me
	 */
	private void bookTableMousePressed(MouseEvent met) {
		int row=this.bookTable.getSelectedRow();
		this.idTxt.setText((String)bookTable.getValueAt(row, 0));
		this.bookNameTxt.setText((String)bookTable.getValueAt(row, 1));
		this.authorTxt.setText((String)bookTable.getValueAt(row, 2));
		String sex=(String)bookTable.getValueAt(row, 3);
		if("男".equals(sex)) {
			this.manJrb.setSelected(true);
		}else if("女".equals(sex)) {
			this.femaleJrb.setSelected(true);
		}
		
		this.priceTxt.setText((Float)bookTable.getValueAt(row, 4)+"");
		this.bookDescTxt.setText((String)bookTable.getValueAt(row, 5));
		String bookTypeName=(String)this.bookTable.getValueAt(row, 6);
		int n=this.bookTypeJcb.getItemCount();
		for(int i=0;i<n;i++) {
			BookType item=(BookType)this.bookTypeJcb.getItemAt(i);
			if(item.getBookTypeName().equals(bookTypeName)) {
				this.bookTypeJcb.setSelectedIndex(i);
			}
		}
		
		String status=(String)bookTable.getValueAt(row, 7);
		if("在馆".equals(status)) {
			this.notBorrowedJrb.setSelected(true);
		}else if("已借".equals(status)) {
			this.borrowedJrb.setSelected(true);
		}
	}
	
	/**
	 * 重置表单
	 */
	private void reSetValue() {
		this.idTxt.setText("");
		this.bookNameTxt.setText("");
		this.authorTxt.setText("");
		this.priceTxt.setText("");
		this.manJrb.setSelected(true);
		this.bookDescTxt.setText("");
		if(this.bookTypeJcb.getItemCount()>0) {
			this.bookTypeJcb.setSelectedIndex(0);
			
		}
	}

	/**
	 * 图书查询事件处理
	 * @param e
	 */
	private void bookSearchActionPerformed(ActionEvent evt) {
		String bookName=this.s_bookNameTxt.getText();
		String author=this.s_authorTxt.getText();
		
		BookType bookType=(BookType) this.s_bookTypeJcb.getSelectedItem();
		int bookTypeId=bookType.getId();
		
		String status="";
		if(s_notBorrowedJrb.isSelected()) {
			status="在馆";
			
		}
		else if(s_borrowedJrb.isSelected()) {
			status="已借";
		}
		
		Book book=new Book(bookName,author,bookTypeId,status);
		this.fillTable(book);
		
		
	}

	/**
	 * 初始下拉框
	 * type 下拉框类型
	 */
	private void fillBookType(String type) {
		Connection con=null;
		BookType bookType=null;
		try {
			con=dbUtil.getCon();
			ResultSet rs=bookTypeDao.list(con, new BookType());
			if("search".equals(type)) {
				bookType=new BookType();
				bookType.setBookTypeName("请选择...");
				bookType.setId(-1);
				this.s_bookTypeJcb.addItem(bookType);
			}
			while(rs.next()) {
				bookType=new BookType();
				bookType.setBookTypeName(rs.getString("bookTypeName"));
				bookType.setId(rs.getInt("id"));
				if("search".equals(type)) {
					this.s_bookTypeJcb.addItem(bookType);
				}
				else if("modify".equals(type)) {
					this.bookTypeJcb.addItem(bookType);
					
				}
			}
			
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	
	/**
	 * 初始化表格数据
	 * @param book
	 */
	private void fillTable(Book book) {
		DefaultTableModel dtm=(DefaultTableModel) bookTable.getModel();
		dtm.setRowCount(0);//设置成0行
		Connection con=null;
		try {
			con=dbUtil.getCon();
			ResultSet rs=bookDao.list(con, book);
			while(rs.next()) {
				Vector v=new Vector();
				v.add(rs.getString("id"));
				v.add(rs.getString("bookName"));
				v.add(rs.getString("author"));
				v.add(rs.getString("sex"));
				v.add(rs.getFloat("price"));
				v.add(rs.getString("bookDesc"));
				v.add(rs.getString("bookTypeName"));
				v.add(rs.getString("status"));
				dtm.addRow(v);
			}
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			try {
				dbUtil.closeCon(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
